import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2023-10-15
 * Time: 21:00
 */
public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int m = in.nextInt();
            int[] dp = new int[m + 1];
            // 动态规划
            Arrays.fill(dp, 100005);
            dp[n] = 0;
            for (int i = n; i <= m; i++) {
                if (dp[i] == 100005) {
                    continue;
                }
                List<Integer> list = new ArrayList<>();
                getList(i, list);
                // 更新能够到达的位置的最小步数
                for (Integer x : list) {
                    if ((i + x) <= m) {
                        dp[i + x] = Math.min(dp[i + x], dp[i] + 1);
                    }
                }
            }
            if (dp[m] == 100005) {
                System.out.println(-1);
            } else {
                System.out.println(dp[m]);
            }
        }
    }

    private static void getList(int v, List<Integer> list) {
        // 注意求 因数的时候进行优化, 不然时间复杂度比较高
        for (int i = 2; i*i <= v; i++) {
            if (v % i == 0) {
                list.add(i);
                list.add(v/i);
            }
        }
    }
}
